package com.atguigu.gmall.product.controller.admin;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.product.service.SpuImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * spu图片表controller层
 */
@RestController
@RequestMapping("/admin/product")
public class SpuImageController {

    @Autowired
    private SpuImageService spuImageService;

    /**
     * 根据spuId查询数据
     * @param spuId
     * @return
     */
    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable("spuId") Long spuId){
        //校验数据
        if(spuId == null){
            throw new GmallException("参数错误！",null);
        }

        //2 调用业务层方法
        List<SpuImage> spuImageList = spuImageService.listBySpuId(spuId);

        //3 响应数据
        return Result.ok(spuImageList);
    }
}
